package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.entity.AlertRule;
import com.zzyl.service.AlertService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description AlertController
 * @Author KangChi Wang
 * @Date 2024-09-14
 */
@RestController
@Slf4j
@RequestMapping("/alert-rule")
public class AlertController {

    @Autowired
    private AlertService alertService;

    //新增报警规则
    @PostMapping("/create")
    public ResponseResult createAlertRule(@RequestBody AlertRuleDto alertRuleDto) {

        alertService.createAlertRule(alertRuleDto);
        return ResponseResult.success();
    }

    @ApiOperation("分页获取告警规则列表")
    @GetMapping("get-page")
    public ResponseResult<PageResponse<AlertRule>> getPage(@RequestParam(value = "pageNum", defaultValue = "1", required = true) int pageNum,
                                                          @RequestParam(value = "pageSize", defaultValue = "10", required = true) int pageSize,
                                                          @RequestParam(value = "AlertRuleName", required = false) String AlertRuleName,
                                                          @RequestParam(value = "functionName", required = false) String functionName,
                                                          @RequestParam(value = "productKey", required = false) String productKey
    ) {
        PageResponse<AlertRule>pages= alertService.getPages(pageNum, pageSize, AlertRuleName, functionName, productKey);
        return ResponseResult.success(pages);
    }
    @ApiOperation("获取单个警告规则")
    @GetMapping("read/{id}")
    public ResponseResult<AlertRule> read(@PathVariable("id") Long id) {
        AlertRule alertRule = alertService.getById(id);
        return ResponseResult.success(alertRule);
    }

}
